<template>
	<view class="contont" style="background-color: #F5F5F5;">
		<view class="infromid">
			<view style="height: 50%;width: 100%;border-bottom: 1px solid #F5F5F5;" class="cent" >
					<text style="font-size: 15px;margin-left: 30rpx;">姓名</text>
					<input type="text"  placeholder="请输入个人姓名" v-model="code"  style="font-size: 15px;width: 30%;margin-right: 15px;text-align: right;"/>
			</view>
			<view style="height: 50%;width: 100%; " class="cent" >
					<text style="font-size: 15px;margin-left: 30rpx;">身份证</text>
					<input type="text"  placeholder="请输入个人身份证号" maxlength="18" v-model="codes"  style="font-size: 15px;width: 50%;margin-right: 15px;text-align: right;"/>
			</view>
		</view>
	<view class="infromeid">
			<view class="cents" style="height: 50%;width: 100%;">
					<text style="height: 100%;margin-left: 30rpx;padding-top: 32px;">驾驶证照片</text>
					<view class="" style="width: 240px;height: 120px;">
						<image src="../../static/img/img_shangchuanxiao@2x.png" mode="" style="width: 100%;height: 100%;overflow: hidden;"  @click="img" v-if="imaged.length==0"></image>
						<image :src="imaged[0]" mode="" style="width: 240px;height: 120px;"  v-if="imaged.length!=0"  @click="img"></image>
					</view>
				
			</view>
			<view class="cents" style="height: 50%;width: 100%;">
					<text style="height: 100%;margin-left: 30rpx;padding-top: 32px;">驾驶证照片</text>
					<image src="../../static/img/img_shangchuan@2x.png" mode="" style="width: 240px;height: 120px;"></image>
			</view>
		</view>
		<button @click="but" style="margin-top: 120rpx;">提交</button>
	</view>
</template>

<script>
	import {ajax} from '../../api.js'
	import { Deiverapis } from '../../Deiverapis.js';
	export default {
		data() {
			return {
				imaged:[],
				codes:"",
				code:"",
				list:[],
				phone:"",
				imgd:"",
				images:[]
			}
		},
		onLoad(option) {
			this.list=option
		},
		
		onShow() {
		uni.showLoading({
		    title: '加载中！'
		});
			// 登录
			var that=this
			Deiverapis({
				url:"/appdriver/loginsubmit",
				data:{
					
					phone:this.list.phone,
					password:this.list.password
				},
					success:function(res){
					
							uni.setStorageSync("sessionid", res.header["Set-Cookie"])	
							ajax({
								url:"/v1/appdriver/user/profile",
								success(res){
								if(res.data.message.username!=""){
									that.code=res.data.message.username
									that.codes=res.data.message.idnumber
									that.imaged.push("https://www.uhuoda.com"+res.data.message.drivingnumaphoto)
									that.images.push("https://www.uhuoda.com"+res.data.message.drivingnumaphoto)
									ajax({
											url:"/v1/appdriver/user/profile",
											success(res){
												if(res.data.message.authstatus==1){
													uni.navigateTo({
										url:"../web/web?idnum="+that.codes+"&name="+that.code+"&phone="+that.list.phone+"&password="+that.list.password
													})
												}
									
								}
								})
								}
								}
							})
							if(res.data.status=="OK"){
								ajax({
										url:"/v1/appdriver/user/profile",
										success(res){
												 console.log(that.images)
											uni.hideLoading()
											if(res.data.message.authstatus==2){
												uni.setStorage({
													key:"name",
													data:{state:res.data.status,
														phone:that.list.phone,
														pass:that.list.password},
														success() {
															uni.getStorage({
																key:"name",
																success:function(res){
																	 that.phone=res.data.phone
																
																	if(that.images.length!=0){
																		uni.reLaunch({
																				 	url:"../Receipt/Receipt"
																					 })
																	}else{
																		var header;
																										  header = { 
																							
																							     'content-type': 'multipart/form-data', 
																							
																							     'cookie':uni.getStorageSync("sessionid")//读取cookie
																							
																							  };
																		const uploadTask = uni.uploadFile({
																		 url : 'https://www.uhuoda.com/v1/appdriver/user/editprofile',
																		 filePath: that.imgd[0],
																		 name: 'driverLicensePhoto',
																		 header:header,
																		 formData: {
																					phone:res.data.phone,
																		  			username:that.code,
																		  			idnumber:that.codes,	
																		 },
																		 success (uploadFileRes) {
																			 uni.hideLoading()
																		 					 uni.reLaunch({
																		 							 	url:"../Receipt/Receipt"
																		 							 })
																		 }
																		});
																			
																	}
																},
															})
														}
												})
												
												
											}else{
												uni.hideLoading()
											}
										}
								})
							}
						}
						
					})
	
		},
		methods: {
			img(){	
					var  _self = this;
				  wx.showActionSheet({
				       itemList: ['拍照','从手机相册选择'],
				    success(res) {
				    
				      if(res.tapIndex==0){ //0是拍照
				        wx.chooseImage({
				          count: 1,
				          sizeType: ['compressed'],
				          sourceType: ['camera'],
				          success: function (res) {
				             _self.imaged= res.tempFilePaths;
				           },
				        })
				      } else if(res.tapIndex==1){
				        wx.chooseImage({
				          count: 1,
				          sizeType: ['compressed'],
				          sourceType: ['album'],
				          success: function(res) {
				          _self.imaged= res.tempFilePaths;
				          },
				        })
				      }
				    }
				  })
							 },
			but(){
				
				if(this.imaged.length==0){
					
					uni.showToast({
					    title:'请选择行驶证',
						icon:"none"
					})
					}else if(this.code==""){
						uni.showToast({
						    title:'请输入姓名',
							icon:"none"
						})
					}else if(this.codes==""){
						uni.showToast({
						    title:'请输入个人身份证',
							icon:"none"
						})
					}else{
							uni.navigateTo({
					url:"../web/web?idnum="+this.codes+"&name="+this.code+"&phone="+this.list.phone+"&password="+this.list.password
				})
					}
			
				this.imgd=this.imaged
			}
		},
	}
</script>

<style>
	page{
		height: 100%;
	}
.infromid{
	width:355px;
	height:111px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
}
 .infromeid{
	width:355px;
	height:285px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	margin-top: 10px;
}
button{
	width:355px;
	height:44px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	color: #FFFFFF;
}
</style>
